#!/bin/bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}"

START_DATE="$(date --date='2 day ago' '+%Y%m%d')"
END_DATE=$(date +%Y%m%d -d "${START_DATE} + 1 day")
if [ -n "${1}" ]; then
  START_DATE="${1}"
  END_DATE=$(date +%Y%m%d -d "${START_DATE} + 1 day")
fi
if [ -n "${2}" ]; then
  END_DATE="${2}"
fi

# venv activate
source "${REPO_ROOT}/venv/bin/activate"
cd python

./pyrunner coin/support/feed_tool/feed_cache/app/instrument_cache_builder.py \
  --start_date=${START_DATE} \
  --end_date=${END_DATE} \
  --machine=feed-01.ap-northeast-1.aws \
  --static_cache_root=/remote/iosg/coin/cache/prod

deactivate
